import { screen, imageResource, keyboard, Key, mouse, centerOf, straightTo, Button, linear } from '@nut-tree/nut-js';
import '@nut-tree/template-matcher';

// 1、添加好友
export default async function addFriend() {
    // 1.1、点击“通讯录”按钮
    let region = await screen.find(imageResource('通讯录-template.png'), { confidence: 0.7 });
    await mouse.move(straightTo(centerOf(region)), linear(500));
    await mouse.click(Button.LEFT);

    // 1.2、点击“添加联系人”按钮
    region = await screen.waitFor(imageResource('添加联系人-template.png'), 6000, 500, { confidence: 0.7 });
    await mouse.move(straightTo(centerOf(region)), linear(500));
    await mouse.click(Button.LEFT);

    // 1.3、输入手机号
    await screen.waitFor(imageResource('添加新联系人输入框手机号-template.png'), 6000, 500, { confidence: 0.7 });
    await keyboard.type('18600774673');
    await keyboard.pressKey(Key.Enter);
    await keyboard.releaseKey(Key.Enter);

    // 1.4、点击“添加”按钮
    region = await screen.waitFor(imageResource('添加按钮-template.png'), 6000, 500, { confidence: 0.7 });
    await mouse.move(straightTo(centerOf(region)), linear(500));
    // await mouse.click(Button.LEFT);

    // // 1.5、点击“发送”按钮
    // region = await screen.waitFor(imageResource('发送-template.png'), 6000, 500, { confidence: 0.7 });
    // await mouse.move(straightTo(centerOf(region)), linear(500));
    // await mouse.click(Button.LEFT);

    // await keyboard.pressKey(Key.Escape);
    // await keyboard.releaseKey(Key.Escape);

    await keyboard.pressKey(Key.Escape);
    await keyboard.releaseKey(Key.Escape);
}